package com.stoneframe.base.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.ModelAndView;

import com.stoneframe.base.cache.CacheManager;
import com.stoneframe.base.util.GuidHelper;
import com.stoneframe.base.util.Logger;
import com.stoneframe.base.util.PageData;

public class BaseController {
	
	private static final long serialVersionUID = 6357869213649815390L;
	
	protected String className=this.getClass().getSimpleName()+".";
	
	protected Logger logger=Logger.getLogger(this.getClass());
	
	/**
	 * 得到request对象
	 */
	public HttpServletRequest getRequest(){
		HttpServletRequest request=((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
		return request;
	}
	
	/**
	 * 得到PageData
	 */
	public PageData getPageData(){
		return new PageData(this.getRequest());
	}
	
	/**
	 * 得到ModelAndView
	 */
	public ModelAndView getModelAndView(){
		return new ModelAndView();
	}
	
	/**
	 * 得到32位的guid
	 * @return
	 */
	public String get32Guid(){
		return GuidHelper.get32Uuid();
	}
	
	/**
	 * 得到当前时间毫秒数 13位
	 * @return
	 */
	public String getTimeUuid(){
		return GuidHelper.getTimeUuid();
	}
	
	/**
	 * 获取当前用户
	 */
	public PageData getCurrentUser(String token){
		return (PageData)CacheManager.getCache(token);
	}
	
	/**
	 * 日志开始
	 */
	public static void logBefore(Logger logger,String intefaceName){
		logger.info("");
		logger.info("start");
		logger.info(intefaceName);
	}
	
	/**
	 * 日志结束
	 */
	public static void logAfter(Logger logger){
		logger.info("end");
		logger.info("");
	}

}
